<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:53:56
 * @LastEditTime: 2023-10-04 00:35:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\System;


use App\Http\Services\Service;

use App\Repositories\MpcLocationRepository;

class MpcLocationService extends Service
    {
    public function __construct(MpcLocationRepository $repository)
        {
        $this->repository = $repository;
        }

    public function list()
        {
        //白纱入库，选择库位会出现外发库位，限制不显示
        $data = $this->repository->whereIs_outsourcing(0)->condition(request())->getGrid();
        return $data;
        }
    public function treelist()
        {
        $data = $this->repository->whereParent_id(0)->with(['children' => $this->repository->getRelation(), 'department'])->getList();
        return $data;
        }
    public function defaultLocation()
        {
        $data = $this->repository->whereDefault(1)->get()->map(function ($v)
            {
            if ($v->department_id == auth()->user()->department_id) {
                $v->selected = true;
                }
            else
                $v->selected = false;
            return $v;
            });
        return $data;
        }
    protected function save($request)
        {
        return $this->repository->autosave($request->toArray());
        }
    protected function delete($request)
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->autodelete();
        }
    }